#include <vector>
#include <iostream>

using namespace std;

class Solution 
{
public:
    vector<int> productExceptSelf(vector<int>& nums) 
    {
        if(nums.empty())
        {
            return {};
        }
        vector<int> right(nums.size());
        right[nums.size() - 1] = 1;
        for(int i = nums.size() - 2; i >= 0; i--)
        {
            right[i] = right[i + 1] * nums[i + 1];
        }
        vector<int> result(nums.size());
        int left = 1;
        for(int i = 0; i < nums.size(); i++)
        {
            result[i] = left * right[i];
            left *= nums[i];
        }
        return result;
    }
};

// 辅助函数：打印数组
void printArray(const vector<int>& nums) 
{
    cout << "[";
    for(int i = 0; i < nums.size(); i++) 
    {
        cout << nums[i];
        if(i < nums.size() - 1) cout << ",";
    }
    cout << "]";
}

int main() 
{
    Solution solution;
    
    // 测试案例1: [1,2,3,4]
    cout << "测试案例1:" << endl;
    vector<int> nums1 = {1, 2, 3, 4};
    cout << "输入: nums = ";
    printArray(nums1);
    cout << endl;
    vector<int> result1 = solution.productExceptSelf(nums1);
    cout << "输出: ";
    printArray(result1);
    cout << endl;
    cout << "期望: [24,12,8,6]" << endl << endl;
    
    // 测试案例2: [-1,1,0,-3,3]
    cout << "测试案例2:" << endl;
    vector<int> nums2 = {-1, 1, 0, -3, 3};
    cout << "输入: nums = ";
    printArray(nums2);
    cout << endl;
    vector<int> result2 = solution.productExceptSelf(nums2);
    cout << "输出: ";
    printArray(result2);
    cout << endl;
    cout << "期望: [0,0,9,0,0]" << endl << endl;
    
    // 测试案例3: 两个元素
    cout << "测试案例3 (两个元素):" << endl;
    vector<int> nums3 = {2, 3};
    cout << "输入: nums = ";
    printArray(nums3);
    cout << endl;
    vector<int> result3 = solution.productExceptSelf(nums3);
    cout << "输出: ";
    printArray(result3);
    cout << endl;
    cout << "期望: [3,2]" << endl << endl;
    
    // 测试案例4: 包含1
    cout << "测试案例4 (包含1):" << endl;
    vector<int> nums4 = {1, 1, 1, 1};
    cout << "输入: nums = ";
    printArray(nums4);
    cout << endl;
    vector<int> result4 = solution.productExceptSelf(nums4);
    cout << "输出: ";
    printArray(result4);
    cout << endl;
    cout << "期望: [1,1,1,1]" << endl << endl;
    
    // 测试案例5: 包含负数
    cout << "测试案例5 (包含负数):" << endl;
    vector<int> nums5 = {-1, -2, -3, -4};
    cout << "输入: nums = ";
    printArray(nums5);
    cout << endl;
    vector<int> result5 = solution.productExceptSelf(nums5);
    cout << "输出: ";
    printArray(result5);
    cout << endl;
    cout << "期望: [-24,-12,-8,-6]" << endl << endl;
    
    // 测试案例6: 单个0
    cout << "测试案例6 (单个0):" << endl;
    vector<int> nums6 = {1, 2, 0, 4};
    cout << "输入: nums = ";
    printArray(nums6);
    cout << endl;
    vector<int> result6 = solution.productExceptSelf(nums6);
    cout << "输出: ";
    printArray(result6);
    cout << endl;
    cout << "期望: [0,0,8,0]" << endl << endl;
    
    // 测试案例7: 多个0
    cout << "测试案例7 (多个0):" << endl;
    vector<int> nums7 = {0, 1, 0, 3};
    cout << "输入: nums = ";
    printArray(nums7);
    cout << endl;
    vector<int> result7 = solution.productExceptSelf(nums7);
    cout << "输出: ";
    printArray(result7);
    cout << endl;
    cout << "期望: [0,0,0,0]" << endl << endl;
    
    // 测试案例8: 大数值
    cout << "测试案例8 (大数值):" << endl;
    vector<int> nums8 = {2, 5, 3, 4};
    cout << "输入: nums = ";
    printArray(nums8);
    cout << endl;
    vector<int> result8 = solution.productExceptSelf(nums8);
    cout << "输出: ";
    printArray(result8);
    cout << endl;
    cout << "期望: [60,24,40,30]" << endl << endl;
    
    // 测试案例9: 正负混合
    cout << "测试案例9 (正负混合):" << endl;
    vector<int> nums9 = {2, -3, 4, -1};
    cout << "输入: nums = ";
    printArray(nums9);
    cout << endl;
    vector<int> result9 = solution.productExceptSelf(nums9);
    cout << "输出: ";
    printArray(result9);
    cout << endl;
    cout << "期望: [12,-8,6,-24]" << endl << endl;
    
    // 测试案例10: 三个元素
    cout << "测试案例10 (三个元素):" << endl;
    vector<int> nums10 = {1, 2, 3};
    cout << "输入: nums = ";
    printArray(nums10);
    cout << endl;
    vector<int> result10 = solution.productExceptSelf(nums10);
    cout << "输出: ";
    printArray(result10);
    cout << endl;
    cout << "期望: [6,3,2]" << endl << endl;
    
    return 0;
}